
// 使用结构体定义结构
struct User{
    name: String,
    age: i32,
}
#[test]
pub fn run() {
    // 1. 实例化结构体
    let user = User{
        name: String::from("张三"),
        age: 18,
    };
    println!("name: {}, age: {}", user.name, user.age);
    
    // 2.定义一个元组，作为结构
    let user2 = ("Tom", 18);
    let user_name = user2.0;
    println!("user2 name: {}", user_name);

    // 3实例化枚举
    let event = WebEvent::KeyPress('a');
    event.describe();

}

// 3.定义枚举作为结构
enum WebEvent {
    // An enum variant without any data.
    PageLoad,
    // An enum variant with a string slice.
    KeyPress(char),
    // An enum variant with a struct.
    Click { x: i32, y: i32 },
    // An enum variant with an owned String.
    Paste(String),
}

impl WebEvent {
    fn describe(&self) {
        match self {
            WebEvent::PageLoad => println!("Page loaded"),
            WebEvent::KeyPress(c) => println!("Key pressed: {}", c),
            WebEvent::Click { x, y } => println!("Clicked at: ({}, {})", x, y),
            WebEvent::Paste(s) => println!("Pasted: {}", s),
        }
    }
}